package com.nwork.cateye;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.RadioGroup;

import com.baidu.mapapi.model.LatLng;
import com.nwork.cateye.baidumap.MyLocation;
import com.nwork.cateye.fragment.CinemaFragment;
import com.nwork.cateye.fragment.CommunityFragment;
import com.nwork.cateye.fragment.MineFragment;
import com.nwork.cateye.fragment.MovieFragment;

public class MainActivity extends ActionBarActivity implements RadioGroup.OnCheckedChangeListener {

    private FrameLayout fragmentContainer;
    private RadioGroup radioGroup;
    private FragmentTransaction transaction;
    private FragmentManager fragmentManager;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        fragmentContainer = (FrameLayout) findViewById(R.id.fragment_container);
        fragmentManager = getSupportFragmentManager();
        transaction = fragmentManager.beginTransaction();
        MovieFragment movieFragment = new MovieFragment();
        transaction.add(R.id.fragment_container, movieFragment);
        transaction.commit();
        radioGroup = (RadioGroup) findViewById(R.id.radio_group);
        radioGroup.setOnCheckedChangeListener(this);

//        MyLocation myLocation = new MyLocation(this);
//        LatLng latLng = myLocation.nameToLatLng("南京");
//        Log.d("++++", "  坐标 == " + latLng.latitude);
//        Log.d("++++", "  坐标 == " + latLng.longitude);
    }


    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.radio_cinema:
                FragmentTransaction cinemaTra = fragmentManager.beginTransaction();
                CinemaFragment cinemaFragment = new CinemaFragment();
                cinemaTra.replace(R.id.fragment_container, cinemaFragment);
                cinemaTra.commit();
                break;
            case R.id.radio_movie:
                FragmentTransaction movieTran = fragmentManager.beginTransaction();
                MovieFragment movieFragment = new MovieFragment();
                movieTran.replace(R.id.fragment_container, movieFragment);
                movieTran.commit();
                break;
            case R.id.radio_community:
                FragmentTransaction commTran = fragmentManager.beginTransaction();
                CommunityFragment communityFragment = new CommunityFragment();
                commTran.replace(R.id.fragment_container, communityFragment);
                commTran.commit();
                break;
            case R.id.radio_mine:
                FragmentTransaction mineTran = fragmentManager.beginTransaction();
                MineFragment mineFragment = new MineFragment();
                mineTran.replace(R.id.fragment_container, mineFragment);
                mineTran.commit();
                break;
        }
    }
}
